package com.am.base;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class ServiceImplBase<T,M extends MapperBase<T>> implements ServiceBase<T>  {
    @Autowired
    private M m;

    public T selectById(Integer id){
        return m.selectByPrimaryKey(id);
    }
    public List<T> selectAll(){
        return m.selectAll();
    }

    @Override
    public PageInfo<T> selectAll(String limit, String page) {

        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<T>  list = m.selectAll();
        PageInfo<T> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    public Integer update(T record){
        return m.updateByPrimaryKey(record);
    }
    public Integer insert(T record){
        return m.insert(record);
    }
    public Integer delete(Integer id){
        return m.deleteByPrimaryKey(id);
    }

    @Override
    public Integer Action(Integer id, String menuActivate) {
        return m.Action(id,menuActivate);
    }

}
